﻿/***********************************************************************************************
 * 
 * ProjectName: WMSSoft.Lib.WinKStart
 * 
 * Description: Menu - Item - Class contains an startmenuitem reading from disk
 * 
 * Created:     10.05.2012
 * 
 * Author:      matthias wagler - matthias@WMSSoft.de
 * 
 * Copyright:   Copyright 2012 by WMSSoft.de
 * 
 * License:     GPLv3
 * 
 * History:     10.05.2012 - matthias wagler matthias@WMSSoft.de   -   Created
 * 
 **********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using IWshRuntimeLibrary;
using System.Runtime.InteropServices;
using WMSSoft.Lib.Basic;
using WMSSoft.Lib.Enums;
using WMSSoft.Lib.Interfaces;

namespace WMSSoft.Lib.WinKStart
{
    /// <summary>
    /// This class representates a Folder of Link in Startmenu
    /// </summary>
    public class cStartmenuItem : iWinKStartItem 
    {
        string _LinkFilename = "";
        string _ItemName = "";
        string _ViewName = "";
        string _UserStartMenuPath = "";
        string _AllUsersStartMenuPath = "";
        string _Filter = "";
        //private string _Target = "";
        string _Comment = "";
        string _Hotkey = "";
        //string _Path = "";
        string _Arguments = "";
        string _WorkingDirectory = "";
        string _Font = "Segoe UI";
        string _FolderPath = "";
        string _GroupID = "";
        //eLinkExecutionTypes _LinkExecutionType = eLinkExecutionTypes.Unknown;
        int _WindowsStyle = 0;
        int _FontSize = 12;
        int _ItemHeight = 32;
        eXMLHorizontalAlign _TextAlign = eXMLHorizontalAlign.Left;
        eXMLVerticalAlign _VerticalAlign = eXMLVerticalAlign.Center;
        eLinkExecutionTypes _ExecutionType = eLinkExecutionTypes.Unknown;
        eExecutionProcedure _ExecutionProcedure = eExecutionProcedure.Unknown;
        eItemType _Itemtype = eItemType.None;
        eContentPanelContentType _ContentType = eContentPanelContentType.None;
        cStartmenuItem _Parent = null;
        BitmapImage _Image;
        System.Drawing.Icon _ItemIcon = null;
        Color _FontColor = Color.FromRgb(0,0,0);
        Dictionary<string, string> _LinkDisplayNames = null;
        Dictionary<string, string> _FolderDisplayNames = null;
        List<String> _FolderItemKeys = null;
        List<String> _LinkItemKeys = null;

        Dictionary<string, object> _ChildItems = null;

        [DllImport("Shell32", CharSet = CharSet.Auto)]
        internal extern static IntPtr ExtractIcon(IntPtr hInst, string lpszFile, int nIconIndex);

        /// <summary>
        /// Create a new instance from this class
        /// </summary>
        public cStartmenuItem()
        {
            try
            {
                //intialise dictionary
                _ChildItems = new Dictionary<string, object>();
                _FolderItemKeys = new List<string>();
                _LinkDisplayNames = new Dictionary<string, string>();
                _FolderDisplayNames = new Dictionary<string, string>();
                _LinkItemKeys = new List<string>();
            }
            catch (Exception ex)
            {
                CMessagelogging.AppendMessage("Error while initialise StartmenuItem!", ex, EMessageTypes.Error);
            }
        }

        /// <summary>
        /// Create a new Instance for this class and give it the values given in Params
        /// </summary>
        /// <param name="Name">Item Name</param>
        /// <param name="Caption">viewing Item caption</param>
        /// <param name="Link">File to Execute</param>
        /// <param name="Type">Item type -> Link or Folder</param>
        /// <param name="Target">Anwendung die ausgeführt werden soll</param>
        /// <param name="Comment">Kommentar</param>
        /// <param name="Hotkey">Tastenkombintation</param>
        /// <param name="Path"></param>
        /// <param name="Arguments"></param>
        /// <param name="Image"></param>
        public cStartmenuItem(string Name, string Caption, eLinkExecutionTypes ExecutionType,
                              string Link, eExecutionProcedure ExecutionProceudre, eItemType Type,
                              string Comment, System.Drawing.Icon ItemIcon, cStartmenuItem Parent,
                              string Arguments, string FolderPath, string UserStartMenuPath,
                              string AllUsersStartMenuPath)
        {
            _ChildItems = new Dictionary<string, object>();
            _LinkDisplayNames = new Dictionary<string, string>();
            _FolderDisplayNames = new Dictionary<string, string>();
            _FolderItemKeys = new List<string>();
            _LinkItemKeys = new List<string>();
            _ExecutionType = ExecutionType;
            _ExecutionProcedure = ExecutionProceudre;
            _ItemName = Name;
            _ViewName = Caption;
            _LinkFilename = Link;
            _Itemtype = Type;
            _Comment = Comment;
            _ItemIcon = ItemIcon;
            _Parent = Parent;
            _Arguments = Arguments;
            _FolderPath = FolderPath;
            _UserStartMenuPath = UserStartMenuPath;
            _AllUsersStartMenuPath = AllUsersStartMenuPath;
        }

        public cStartmenuItem(string Name, string Caption, eLinkExecutionTypes ExecutionType,
                              string Link, eExecutionProcedure ExecutionProceudre, eItemType Type,
                              string Comment, System.Drawing.Icon ItemIcon, cStartmenuItem Parent,
                              string Arguments, string Hotkey, string WorkingDir, int WindowsStyle,
                              string UserStartMenuPath, string AllUsersStartMenuPath)
        {
            _ChildItems = new Dictionary<string, object>();
            _LinkDisplayNames = new Dictionary<string, string>();
            _FolderDisplayNames = new Dictionary<string, string>();
            _FolderItemKeys = new List<string>();
            _LinkItemKeys = new List<string>();
            _ExecutionType = ExecutionType;
            _ExecutionProcedure = ExecutionProceudre;
            _ItemName = Name;
            _ViewName = Caption;
            _LinkFilename = Link;
            _Itemtype = Type;
            _Comment = Comment;
            _ItemIcon = ItemIcon;
            _Parent = Parent;
            _Arguments = Arguments;
            _Hotkey = Hotkey;
            _WorkingDirectory = WorkingDir;
            _WindowsStyle = WindowsStyle;
            _UserStartMenuPath = UserStartMenuPath;
            _AllUsersStartMenuPath = AllUsersStartMenuPath;
        }

        public cStartmenuItem(string Name, string Caption, eLinkExecutionTypes ExecutionType,
                              string Link, eExecutionProcedure ExecutionProceudre, eItemType Type,
                              string Comment, System.Drawing.Icon ItemIcon, cStartmenuItem Parent,
                              string Arguments, string Hotkey, string WorkingDir, int WindowsStyle,
                              string Font, int FontSize, Color FontColor,
                              int ItemHeight, eXMLHorizontalAlign TextAlign,
                              eXMLVerticalAlign VerticalAlign, string UserStartMenuPath, 
                              string AllUsersStartMenuPath, string GroupID = "")
        {
            _ChildItems = new Dictionary<string, object>();
            _LinkDisplayNames = new Dictionary<string, string>();
            _FolderDisplayNames = new Dictionary<string, string>();
            _FolderItemKeys = new List<string>();
            _LinkItemKeys = new List<string>();
            _ExecutionType = ExecutionType;
            _ExecutionProcedure = ExecutionProceudre;
            _ItemName = basic_helpers.ReplaceInvalidNameChars(Name);
            _ViewName = Caption;
            _LinkFilename = Link;
            _Itemtype = Type;
            _Comment = Comment;
            _ItemIcon = ItemIcon;
            _Parent = Parent;
            _Arguments = Arguments;
            _Hotkey = Hotkey;
            _WorkingDirectory = WorkingDir;
            _WindowsStyle = WindowsStyle;
            _Font = Font;
            _FontSize = FontSize;
            _FontColor = FontColor;
            _ItemHeight = ItemHeight;
            _TextAlign = TextAlign;
            _VerticalAlign = VerticalAlign;
            _UserStartMenuPath = UserStartMenuPath;
            _AllUsersStartMenuPath = AllUsersStartMenuPath;
            _GroupID = GroupID;
        }

        public cStartmenuItem(string Name, string Caption, eLinkExecutionTypes ExecutionType,
                              string Link, eExecutionProcedure ExecutionProceudre, eItemType Type,
                              string Comment, BitmapImage Image, System.Drawing.Icon ItemIcon, cStartmenuItem Parent,
                              string Arguments, string Hotkey, string WorkingDir, int WindowsStyle,
                              string Font, int FontSize, Color FontColor,
                              int ItemHeight, eXMLHorizontalAlign TextAlign,
                              eXMLVerticalAlign VerticalAlign, string UserStartMenuPath,
                              string AllUsersStartMenuPath, string GroupID = "", string Filter = "")
        {
            _ChildItems = new Dictionary<string, object>();
            _LinkDisplayNames = new Dictionary<string, string>();
            _FolderDisplayNames = new Dictionary<string, string>();
            _FolderItemKeys = new List<string>();
            _LinkItemKeys = new List<string>();
            _ExecutionType = ExecutionType;
            _ExecutionProcedure = ExecutionProceudre;
            _ItemName = basic_helpers.ReplaceInvalidNameChars(Name);
            _ViewName = Caption;
            _LinkFilename = Link;
            _Itemtype = Type;
            _Comment = Comment;
            _ItemIcon = ItemIcon;
            _Image = Image;
            _Parent = Parent;
            _Arguments = Arguments;
            _Hotkey = Hotkey;
            _WorkingDirectory = WorkingDir;
            _WindowsStyle = WindowsStyle;
            _Font = Font;
            _FontSize = FontSize;
            _FontColor = FontColor;
            _ItemHeight = ItemHeight;
            _TextAlign = TextAlign;
            _VerticalAlign = VerticalAlign;
            _UserStartMenuPath = UserStartMenuPath;
            _AllUsersStartMenuPath = AllUsersStartMenuPath;
            _GroupID = GroupID;
            _Filter = Filter;
        }

        #region Public Methods

        /// <summary>
        /// Copy this instance to a new instance
        /// </summary>
        /// <returns></returns>
        public iWinKStartItem Copy()
        {
            try
            {
                cStartmenuItem resultItem = new cStartmenuItem(this.ItemName, this.ViewName, this.ExecutionType, this.LinkFilename, this.ExecutingProcedure, this.ItemType, "",
                                                               this.ItemIcon, (cStartmenuItem)this.Parent, this.Arguments,this.HotKey,this.WorkingDirectory, this.WindowsStyle, this.FontName,
                                                               this.FontSize,this.FontColor, this.ItemHeight, this._TextAlign , this._VerticalAlign , this.UserStartMenuPath, 
                                                               this.AllUsersStartMenuPath,this.GroupID);
                return resultItem;
            }
            catch (Exception ex)
            {
                //It is not fine, her was an error. In this case we give no instance return
                CMessagelogging.AppendMessage("Can't Copy MenuItem - Instance!", ex, EMessageTypes.Error);
                return null;
            }
        }
        
        /// <summary>
        /// This Method create a new StartmenuItem Instance from an given Item (Filesystem - Object)
        /// </summary>
        /// <param name="Item">a Filesystem - Object </param>
        /// <returns>StartmenuItem instance, null if an error has been found</returns>
        public static cStartmenuItem MakeInstance(string Item, cStartmenuItem Parent, bool LoadImage = true)
        {
            try
            { 
                //before we can create a new object instance, we must test, which type of Item we have an it does exist
                if (System.IO.Path.HasExtension(Item) == true)
                {
                    //this Item contains an extension, also we have a File
                    if (System.IO.File.Exists(Item) == true && System.IO.Path.GetExtension(Item).ToUpper() == ".LNK" )
                    {
                        //Create shellobject to read link files (*.lnk)
                        WshShell shell = new WshShell();
                        //read link file
                        WshShortcut myLink = (WshShortcut)shell.CreateShortcut(Item);
                        WMSSoft.Lib.Shell.FileIcon myLinkInfo = new WMSSoft.Lib.Shell.FileIcon(Item);

                        string stmpDisplayName = myLinkInfo.DisplayName;

                        if (stmpDisplayName.Length == 0)
                            stmpDisplayName = System.IO.Path.GetFileNameWithoutExtension(Item);

                        System.Drawing.Icon ItemIcon = System.Drawing.Icon.FromHandle(WMSSoft.Lib.WinKStart.Properties.Resources.Executable.GetHicon());                        
                        BitmapImage myBImg = basic_GraphicHelpers.WPFBitmapFromDrawingImage(WMSSoft.Lib.WinKStart.Properties.Resources.Executable);

                        bool PathIsDirectory = false;                        

                        if (System.IO.File.Exists(myLink.TargetPath) == false && System.IO.Directory.Exists(myLink.TargetPath) == true)
                        {
                            System.IO.FileAttributes PathAttributes = System.IO.File.GetAttributes(myLink.TargetPath);
                            if ((PathAttributes & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
                                PathIsDirectory = true;
                        }
                        

                        if (PathIsDirectory == false)
                        {

                            try
                            {
                                if (LoadImage == true)
                                {
                                    if (System.IO.File.Exists(myLink.TargetPath) == true)
                                    {
                                        WMSSoft.Lib.Shell.FileIcon myLinkIconInfo = new WMSSoft.Lib.Shell.FileIcon(myLink.TargetPath, WMSSoft.Lib.Shell.FileIcon.SHGetFileInfoConstants.SHGFI_ICON | WMSSoft.Lib.Shell.FileIcon.SHGetFileInfoConstants.SHGFI_ATTRIBUTES);
                                        ItemIcon = myLinkIconInfo.ShellIcon;
                                        myBImg = basic_GraphicHelpers.GetWPFImageFromIcon(myLinkIconInfo.ShellIcon);
                                    }
                                    else
                                    {
                                        WMSSoft.Lib.Shell.FileIcon myLinkIconInfo = new WMSSoft.Lib.Shell.FileIcon(myLink.FullName, WMSSoft.Lib.Shell.FileIcon.SHGetFileInfoConstants.SHGFI_ICON | WMSSoft.Lib.Shell.FileIcon.SHGetFileInfoConstants.SHGFI_ATTRIBUTES);

                                        ItemIcon = myLinkIconInfo.ShellIcon;
                                        myBImg = basic_GraphicHelpers.GetWPFImageFromIcon(myLinkIconInfo.ShellIcon);
                                    }
                                }
                                else
                                {
                                    if (System.IO.File.Exists(myLink.TargetPath) == true)
                                    {
                                        ItemIcon = System.Drawing.Icon.ExtractAssociatedIcon(myLink.TargetPath);
                                        myBImg = basic_GraphicHelpers.GetWPFImageFromIcon(System.Drawing.Icon.ExtractAssociatedIcon(myLink.TargetPath));
                                    }
                                    else
                                        ItemIcon = null;
                                        myBImg = null;

                                }
                            }
                            catch (Exception ex)
                            {
                                ItemIcon = System.Drawing.Icon.FromHandle(WMSSoft.Lib.WinKStart.Properties.Resources.unknown_filetype.GetHicon());
                                myBImg = basic_GraphicHelpers.WPFBitmapFromDrawingImage(WMSSoft.Lib.WinKStart.Properties.Resources.unknown_filetype);
                            }

                            //nice, file does exist, lets go to create a new object instance

                            return new cStartmenuItem(myLink.FullName,
                                                      stmpDisplayName,
                                                      eLinkExecutionTypes.Program, myLink.TargetPath, eExecutionProcedure.Unknown,
                                                      eItemType.Link, myLink.Description, ItemIcon,
                                                      Parent, myLink.Arguments, myLink.Hotkey,
                                                      myLink.WorkingDirectory, myLink.WindowStyle, Parent.UserStartMenuPath, Parent.AllUsersStartMenuPath);
                        }
                        else
                        {
                            //Ok, directory does exist, now we can create an object
                            int iLastSepPos = Item.LastIndexOf(@"\", Item.Length - 1);
                            string DirectoryName = "";

                            if (iLastSepPos > -1)
                            {
                                DirectoryName = Item.Substring(iLastSepPos + 1, Item.Length - (iLastSepPos + 1));
                            }
                            else DirectoryName = Item;

                            //if here are backslash sings in directory name, replace it
                            DirectoryName = DirectoryName.Replace(@"\", "");

                            string sRelativeItemPath = Item;
                            if (sRelativeItemPath.Contains(Parent.UserStartMenuPath) == true)
                            {
                                if (sRelativeItemPath.Length > Parent.UserStartMenuPath.Length)
                                    sRelativeItemPath = Item.Substring(Parent.UserStartMenuPath.Length + 1, Item.Length - (Parent.UserStartMenuPath.Length) - 1);
                            }
                            else if (sRelativeItemPath.Contains(Parent.AllUsersStartMenuPath) == true)
                            {
                                if (sRelativeItemPath.Length > Parent.AllUsersStartMenuPath.Length)
                                    sRelativeItemPath = Item.Substring(Parent.AllUsersStartMenuPath.Length + 1, Item.Length - (Parent.AllUsersStartMenuPath.Length) - 1);
                            }

                            //Create the Object instance 
                            return new cStartmenuItem(basic_helpers.ReplaceInvalidNameChars(DirectoryName), stmpDisplayName,
                                                      eLinkExecutionTypes.Program, "", eExecutionProcedure.Unknown, eItemType.Folder,
                                                      "", ItemIcon, Parent, "", sRelativeItemPath, Parent.UserStartMenuPath, Parent.AllUsersStartMenuPath);
                        }
                                            
                       
                    }
                    else
                    {
                        //this file doesn't exist, we can't create an object instance
                        return null;
                    }
                }
                else
                {
                    //in other case, it must be a directory, best way to test this is, we check this directory does exist
                    if (System.IO.Directory.Exists(Item) == true)
                    {
                        System.Drawing.Icon ItemIcon = System.Drawing.Icon.FromHandle(WMSSoft.Lib.WinKStart.Properties.Resources.Folder.GetHicon());

                        WMSSoft.Lib.Shell.FileIcon myDirInfo = new WMSSoft.Lib.Shell.FileIcon(Item);
                        ItemIcon = myDirInfo.ShellIcon;

                        //Ok, directory does exist, now we can create an object
                        int iLastSepPos = Item.LastIndexOf(@"\", Item.Length - 1);
                        string DirectoryName = "";

                        if (iLastSepPos > -1)
                        {
                            DirectoryName = Item.Substring(iLastSepPos + 1, Item.Length - (iLastSepPos + 1));
                        }
                        else DirectoryName = Item;

                        //if here are backslash sings in directory name, replace it
                        DirectoryName = DirectoryName.Replace(@"\", "");

                        string sRelativeItemPath = Item;
                        if (sRelativeItemPath.Contains(Parent.UserStartMenuPath) == true)
                        {
                            if (sRelativeItemPath.Length > Parent.UserStartMenuPath.Length)
                                sRelativeItemPath = Item.Substring(Parent.UserStartMenuPath.Length + 1, Item.Length - (Parent.UserStartMenuPath.Length) - 1);
                        }
                        else if (sRelativeItemPath.Contains(Parent.AllUsersStartMenuPath) == true)
                        {
                            if (sRelativeItemPath.Length > Parent.AllUsersStartMenuPath.Length)
                                sRelativeItemPath = Item.Substring(Parent.AllUsersStartMenuPath.Length + 1, Item.Length - (Parent.AllUsersStartMenuPath.Length) - 1);
                        }

                        //Create the Object instance 
                        return new cStartmenuItem(basic_helpers.ReplaceInvalidNameChars(DirectoryName), myDirInfo.DisplayName, 
                                                  eLinkExecutionTypes.Program, "", eExecutionProcedure.Unknown, eItemType.Folder,
                                                  "", ItemIcon, Parent, "", sRelativeItemPath, Parent.UserStartMenuPath, Parent.AllUsersStartMenuPath);
                    }
                    else
                    {
                        //Directory doesn't exist or is no directory, we can't create an new StartmenuItem - Object
                        return null;
                    }
                }
            }
            catch (Exception ex)
            {
                //It is not fine, her was an error. In this case we give no instance return
                CMessagelogging.AppendMessage("Can't make StartmenuItem instance! Process Item '" + Item + "'", ex, EMessageTypes.Error);
                return null;
            }
            
        }

        /// <summary>
        /// Adds a child to the StartmenuItem
        /// </summary>
        /// <param name="Item">Item to add</param>
        public bool AddChild(iWinKStartItem Item)
        {
            try
            {
                if (Item != null)
                {
                    if (_ChildItems != null && _ChildItems.ContainsKey(Item.ItemName.ToUpper()) == false)
                    {
                        //if this doesn't exist in List, we can add it
                        _ChildItems.Add(Item.ItemName.ToUpper(), Item);
                    }
                    //If item is a folder item, we add it additional to the folderkeys list
                    if (_FolderItemKeys != null && (Item.ItemType == eItemType.Folder | Item.ItemType == eItemType.Filter) && _FolderItemKeys.Contains(Item.ViewName) == false)
                    {
                        _FolderItemKeys.Add(Item.ViewName);
                        _FolderDisplayNames.Add(Item.ViewName, Item.ItemName.ToUpper());
                    }

                    //If item is a link item, we add it additional to the linkkeys list
                    if (_LinkItemKeys != null && (Item.ItemType == eItemType.Link | Item.ItemType == eItemType.Label) && _LinkItemKeys.Contains(Item.ViewName) == false)
                    {
                        _LinkItemKeys.Add(Item.ViewName);
                        _LinkDisplayNames.Add(Item.ViewName, Item.ItemName.ToUpper());
                    }
                    
                    return true;
                }
                else return false;
            }
            catch (Exception ex)
            {
                //add errormessage to messagebus
                CMessagelogging.AppendMessage("Can't add childitem! ", ex, EMessageTypes.Error);
                return false;
            }
        }

        public bool AddChilds(Dictionary<string, object> Childs) 
        {
            try {
                if (Childs != null)
                {
                    Dictionary<string, object>.KeyCollection ChildItemKeys = Childs.Keys;
                    foreach (string Item in ChildItemKeys)
                    {
                        AddChild((cStartmenuItem)Childs[Item]);
                    }
                    return true;
                }
                else return false;

            }
            catch (Exception ex)
            {
                //add errormessage to messagebus
                CMessagelogging.AppendMessage("Can't add childitems! ", ex, EMessageTypes.Error);
                return false;
            }
        }

        public void RemoveChild(string Key)
        {
            try
            {
                //child dictionary contains searched Key 
                if (ChildItems.ContainsKey(Key.ToUpper()) == true)
                {
                    //get item viewname
                    string ItemViewname = ((cStartmenuItem)ChildItems[Key.ToUpper()]).ViewName;
                    //yes, we remove the item from 3 dictionaries: Childitems, LinkDisplayNames and LinkItemList
                    ChildItems.Remove(Key.ToUpper());
                    if (ChildItems.ContainsKey(Key.ToUpper()) == false)
                    {
                        LinkDisplayNames.Remove(ItemViewname);
                        LinkItemList.Remove(ItemViewname);
                    }
                }
            }
            catch (Exception ex)
            {
                //add errormessage to messagebus
                CMessagelogging.AppendMessage("Can't remove childitem! ", ex, EMessageTypes.Error);                
            }
        }

        /// <summary>
        /// Delete all Child Elements from Item. Please use this Methode to clean Item and not the Clear from ChildItems!
        /// </summary>
        public void Clear()
        {
            try
            {
                ChildItems.Clear();
                LinkDisplayNames.Clear();
                LinkItemList.Clear();
            }
            catch (Exception Ex)
            {
                throw new Exception("Can't Delete Child Items!", Ex);
            }
        }

        #endregion

        #region Properties

        public string Filter
        {
            get { return _Filter; }
            set { _Filter = value; }
        }

        public string GroupID
        {
            get { return _GroupID; }
            set { _GroupID = value; }
        }

        public eContentPanelContentType ContentType
        {
            get { return _ContentType; }
            set { _ContentType = value; }
        }

        public string UserStartMenuPath
        {
            get { return _UserStartMenuPath; }
            set { _UserStartMenuPath = value; }
        }

        public string AllUsersStartMenuPath
        {
            get { return _AllUsersStartMenuPath; }
            set { _AllUsersStartMenuPath = value; }
        }

        public string FolderPath
        {
            get { return _FolderPath; }
        }

        /// <summary>
        /// Returns the arguments saved in the object
        /// </summary>
        public string Arguments
        {
            get { return _Arguments; }
            set { _Arguments = value; }
        }
        /// <summary>
        /// The Property spezify the Link - Name to Execute the Program. 
        /// This is empty if the Itemtype is Folder or None.
        /// </summary>
        public string LinkFilename
        {
            get { return _LinkFilename; }
            //set { _LinkFilename = value; }
        }

        /// <summary>
        /// This Property spezify the Name of an Item used in Dictionary
        /// </summary>        
        public string ItemName
        {
            get { return _ItemName; }
            set { _ItemName = value; }
        }

        /// <summary>
        /// This Property contains the Caption of the Item that showing to the user
        /// </summary>
        public string ViewName
        {
            get { return _ViewName; }
            set { _ViewName = value; }
        }

        /// <summary>
        /// this Property describe the Type of this Item Link or Folder
        /// </summary>
        public eItemType ItemType
        {
            get { return _Itemtype; }
            set { _Itemtype = value; }
        }

        /// <summary>
        /// Contains all Link - Items for a Folder.
        /// </summary>
        public Dictionary<string, object> ChildItems
        {
            get { return _ChildItems; }
            //set { _ChildItems = value; }
        }

        /// <summary>
        /// Contains all items names for links by her displayname
        /// </summary>
        public Dictionary<string, string> FolderDisplayNames
        {
            get
            {
                return _FolderDisplayNames;
            }
        }

        public Dictionary<string, string> LinkDisplayNames
        {
            get
            {
                return _LinkDisplayNames;
            }
        }

        /// <summary>
        /// Contains a List with all ChildItem from Type Folder
        /// </summary>
        public List<string> FolderItemKeys
        {
            get { return _FolderItemKeys; }
        }
         
        /// <summary>
        /// Return the Image used for this Item
        /// </summary>
        public BitmapImage Image
        {
            get { return _Image; }
            set { _Image = value; }
        }

        public System.Drawing.Icon ItemIcon
        {
            get { return _ItemIcon; }
        }

        /// <summary>
        /// Contains a List with all ChildItem from Type Link
        /// </summary>
        public List<string> LinkItemList
        {
            get { return _LinkItemKeys; }
            set {_LinkItemKeys = value;}
        }

        /// <summary>
        /// Get the Items parent
        /// </summary>
        public iWinKStartItem Parent
        {
            get { return _Parent; }
        }

        /// <summary>
        /// Gets the full MenuPath for this FolderItem
        /// </summary>
        public string FolderMenuPath
        {
            get
            {
                string sFolderPath = "";
                if (_Itemtype == eItemType.Folder| _Itemtype == eItemType.Filter)
                {

                    //if parent is not set this is the RootItem
                    if (_Parent != null)
                    {
                        //the parent can't be the root item
                        if (_Parent.ItemName.ToUpper().Contains("ROOT") == false )
                        {
                            sFolderPath += _Parent.FolderMenuPath + @"\";
                        }
                        
                    }
                    sFolderPath += _ItemName;// _ViewName;
                }
                return sFolderPath;
            }
        }

        /// <summary>
        /// Return the WorkingDirectory for this Item
        /// </summary>
        public string WorkingDirectory
        {
            get { return _WorkingDirectory; }
            set { _WorkingDirectory = value; }
        }

        /// <summary>
        /// Return the HotKey for this Item
        /// </summary>
        public string HotKey
        {
            get { return _Hotkey; }
            set { _Hotkey = value;}
        }

        /// <summary>
        /// Returns the WindowsStyle used for this Item
        /// </summary>
        public int WindowsStyle
        {
            get { return _WindowsStyle; }
        }

        /// <summary>
        /// Returns the kind of link execution
        /// </summary>
        public eLinkExecutionTypes ExecutionType
        {
            get { return _ExecutionType; }
            set { _ExecutionType = value; }
        }

        /// <summary>
        /// Returns the procedure executing by the link
        /// </summary>
        public eExecutionProcedure ExecutingProcedure
        {
            get { return _ExecutionProcedure; }
            set { _ExecutionProcedure = value; }
        }

        /// <summary>
        /// Return the vertical align for text and image object in ListItem
        /// </summary>
        public System.Windows.VerticalAlignment VerticalAlign
        {
            get
            {
                switch (_VerticalAlign)
                {
                    case eXMLVerticalAlign.Top: return System.Windows.VerticalAlignment.Top;
                    case eXMLVerticalAlign.Center: return System.Windows.VerticalAlignment.Center;
                    case eXMLVerticalAlign.Bottom: return System.Windows.VerticalAlignment.Bottom;
                    default: return System.Windows.VerticalAlignment.Top;
                }
            }
        }

        /// <summary>
        /// Returns the Height for Listbox Item
        /// </summary>
        public int ItemHeight
        {
            get { return _ItemHeight; }
        }

        public System.Windows.TextAlignment TextAlign
        {
            get
            {
                switch (_TextAlign)
                {
                    case eXMLHorizontalAlign.Left: return System.Windows.TextAlignment.Left;
                    case eXMLHorizontalAlign.Center: return System.Windows.TextAlignment.Center;
                    case eXMLHorizontalAlign.Right: return System.Windows.TextAlignment.Right;
                    case eXMLHorizontalAlign.Justify: return System.Windows.TextAlignment.Justify;
                    default: return System.Windows.TextAlignment.Left;
                }
            }
        }

        /// <summary>
        /// Return fontsize used for item text
        /// </summary>
        public int FontSize
        {
            get { return _FontSize; }
        }

        /// <summary>
        /// Returns the Fontname used for this item
        /// </summary>
        public string FontName
        {
            get { return _Font; }
        }

        /// <summary>
        /// Returns the forecolor used for this item
        /// </summary>
        public Color FontColor
        {
            get { return _FontColor; }
        }

        #endregion

        #region Private

        static BitmapImage GetShurtCutImage(string File, int IconIndex)
        {
            try
            {
                IntPtr hc;                
                hc = ExtractIcon(IntPtr.Zero, File, IconIndex);                
                   
                if (!hc.Equals(IntPtr.Zero))
                {
                    BitmapSource myBSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(hc,
                                                                                                        System.Windows.Int32Rect.Empty,
                                                                                                        BitmapSizeOptions.FromEmptyOptions());                  

                    BitmapImage myBImage = new BitmapImage();
                    

                    // myIcon.ToBitmap();
                    return myBImage;
                }
                else return null;
            }
            catch (Exception ex)
            {
                CMessagelogging.AppendMessage("Can't read shurtcutimage! ", ex, EMessageTypes.Error);
                return null;
            }
        }

        #endregion

    }
}
